<script setup>
import { ref, onMounted } from 'vue'
import { Edit, Delete } from '@element-plus/icons-vue'

onMounted(() => {
    getBattery()
})

const tableData = ref([])

const getBattery = async () => {
    //初始化
    let first = function (callback) {
        var c1 = new cloud.Cloud({
            //必填，表示是未登录模式
            identityless: true,
            //资源方 AppID
            resourceAppid: 'wx026afb68a8e326e4',
            //资源方环境 ID
            resourceEnv: 'djcx-ak88-3gjvcbn22ca54f8e',
        })
        c1.init()
        //回调
        callback(c1)
    };
    //完成初始化后再回调，即可访问云数据库
    let callback = function (c1) {
        // 我个人不喜欢写云函数，所以直接写在Web这里做操作
        // 你要访问的各种操作写在这个callback函数里即可，这里以查询users表为例
        const db = c1.database();
        db.collection('battery').get({
            success: res => {
                console.log(res.data)
                tableData.value = res.data
                console.log(tableData.value)
            },
            fail: res => {
                console.log(res);
            }
        })
    };
    first(callback);
}
const del = (row) => {
    console.log(row._id)
    //初始化

    var c1 = new cloud.Cloud({
        //必填，表示是未登录模式
        identityless: true,
        //资源方 AppID
        resourceAppid: 'wx026afb68a8e326e4',
        //资源方环境 ID
        resourceEnv: 'djcx-ak88-3gjvcbn22ca54f8e',
    })
    c1.init({
        env: "djcx-ak88-3gjvcbn22ca54f8e"
    })

    c1.callFunction({
        name: 'delBattery',
        data: {
            name: 'orders',
            id: row._id
        },
        success: res => {
            console.log(res);
            getBattery()
        },
        fail: res => {
            console.log(res);
        }
    })
}
</script>
<template>
    city
</template>